const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    radio:'1',
    radioType:'1',
    propertyPermission:true,//0私盘 1共盘

    cooperationAmount:0,
    cooperationProportion:0,

  },
  attached(){
    console.log("组件进入时渲染", app.globalData.tmp  );
    this.setData({ tmp: app.globalData.tmp,
     radio : app.globalData.tmp.propertyStatus,
     propertyPermission: app.globalData.tmp.propertyPermission?true:false,
     radioType:  app.globalData.tmp.cooperationType ,
     cooperationAmount:  app.globalData.tmp.cooperationAmount ,
     cooperationProportion:  app.globalData.tmp.cooperationProportion ,
     });
 }, 
  /**
   * 组件的方法列表
   */
  methods: {
    onChange(e){ 
      this.setData({ radio:e.detail })
      app.globalData.tmp.propertyStatus = e.detail
    },
    onChangeType(e){ 
      this.setData({ radioType:e.detail })
      app.globalData.tmp.cooperationType = e.detail
    },
    onChangeValue(e) {
      console.log(e.currentTarget.dataset.prop,e.detail.value)   
      var value = parseFloat(e.detail.value).toFixed(2)
      if( e.currentTarget.dataset.prop == 'cooperationProportion'){
        this.setData({ cooperationProportion: value,})
        app.globalData.tmp.cooperationProportion = value
      }else{
        this.setData({cooperationAmount: value })  
        app.globalData.tmp.cooperationAmount = value
      }
    }, 
    bindchangeSwitch(e){
     console.log(e.detail);
     this.setData({propertyPermission:e.detail.value})
     app.globalData.tmp.propertyPermission = e.detail.value
    },
    handleInput(e) {
      console.log("handleInput()",e.currentTarget.dataset.prop,e.detail.value)   
      let value = this.validateNumber(e.detail.value)
      if(value=='') value = 0;
      if( e.currentTarget.dataset.prop == 'cooperationProportion'){
        if(value > 100) value = 100;
        this.setData({ cooperationProportion: value,})
        app.globalData.tmp.cooperationProportion = value
      }else{
        this.setData({cooperationAmount: value })  
        app.globalData.tmp.cooperationAmount = value
      }
    },
    validateNumber(val) {
       return val.replace(/\D/g, '')
    },
  }
})
